<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>


</head>
<body>
<%@ page import = "java.sql.*, java.util.*" %>
<%

String jdbcUrl = "jdbc:mysql://localhost/theater?useUnicode=true&characterEncoding=EUC_KR";;
String dbUser = "root";
String dbPass = "apmsetup";


request.setCharacterEncoding("utf-8");

String id = request.getParameter("id");
String password = request.getParameter("password");
String mem_id=null;
String mem_Pwd=null;

String ad_id = null;
String ad_ps = null;

Connection con = null;
Statement stmt = null;
Statement stmt1 = null;
String sql;
ResultSet rs;
ResultSet admin;
int flag = 0;

try {
	Class.forName("com.mysql.jdbc.Driver");
	con = DriverManager.getConnection(jdbcUrl, dbUser, dbPass);
	stmt=con.createStatement();
	stmt1=con.createStatement();
	rs = stmt.executeQuery("Select CustomerId, Password from customer");
    admin = stmt1.executeQuery("Select * from admin");
    
	while(rs.next()){
		mem_id = rs.getString("CustomerID");
		mem_Pwd = rs.getString("Password");
		
		while(admin.next()){
			ad_id = admin.getString("AdminID");
			ad_ps = admin.getString("A_Password");
			
			if(ad_id.compareTo(id) == 0 && ad_ps.compareTo(password) == 0){
				
				session.setAttribute("ID", id);
				session.setAttribute("passw", mem_Pwd);
				out.print("<script>");
				//out.print("document.onload=function(){<form name='id_info' method='POST' action='mainframe.jsp'><input type='hidden' name='id_inf' value='"+mem_id+"'></form>}");
				out.print("location.href='admin/admin_mainframe.jsp';");
				out.print("</script>");
				flag=1;
			}
		}
		
		if(mem_id.compareTo(id) == 0 && mem_Pwd.compareTo(password) == 0){
			
			session.setAttribute("ID", id);
			session.setAttribute("passw", mem_Pwd);
			out.print("<script>");
			//out.print("document.onload=function(){<form name='id_info' method='POST' action='mainframe.jsp'><input type='hidden' name='id_inf' value='"+mem_id+"'></form>}");
			out.print("location.replace('custom/mainframe.jsp');");
			out.print("</script>");
			flag=1;
		}
	}
	
	if((mem_id.compareTo(id)!=0 || mem_Pwd.compareTo(password)!=0) && flag == 0){
		out.print("<script>");	
		out.print("alert('존재안함');");
		out.print("location.replace('sign_in.jsp');");
		out.print("</script>");	
	} 
	rs.close();
	admin.close();
	stmt.close();
	stmt1.close();
	con.close();
	
} catch (SQLException e) {
	e.printStackTrace();
} finally {

	if(stmt != null)
		try {
			stmt.close();
			stmt1.close();
		} catch (Exception e) {}
	if(con != null)
		try {
			con.close();
		} catch (Exception e) {}
}
%>

</body>
</html>